/*
 * vim: ft=javascript
 */

const path = require('path');
const fs = require('fs');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');

const PATHS = {
  root: __dirname,
  src: path.join(__dirname, '../src'),
  dist: path.join(__dirname, '../dist')
}

module.exports = {
  mode: 'development',
  devtool: 'source-map',
  devServer: {
    static: {
      serveIndex: true,
      directory: path.join(__dirname, 'dist'),
    },
    compress: false,
    port: 9000,
  },
  externals: {
    paths: PATHS
  },
  entry: {
    app: PATHS.src,
    //module: `${PATHS.src}/index.js`
  },
  output: {
    //    filename: `${PATHS.dist}/bundle.js`,
    path: PATHS.dist,
    filename: 'bundle.js'
  },
  resolve: {
    modules: ['src', 'node_modules'],
    alias: {
      '~': PATHS.src,
//      '@': `${PATHS.src}/js`
    }
  },
  plugins: [
    new HtmlWebpackPlugin({
      filename: `index.html`
    }),
    new MiniCssExtractPlugin()
  ],
  module: {
    rules: [
      {
        test: /\.html$/i,
        loader: 'html-loader',
        generator: {
          filename: '[name][ext]',
        },
      },
      {
        test: /\.(js|jsx)$/,
        exclude: /node_modules/,
        use: {
          loader: 'babel-loader',
          options: {
            sourceMap: true
          }
        }
      },

      {
        test: /\.(woff(2)?|ttf|eot|svg)(\?v=\d+\.\d+\.\d+)?$/,
        loader: 'file-loader'
      },
      {
        test: /\.scss|\.sass$/,
        use: [
          'style-loader',
          {
            loader: "css-loader",
            options: {
              sourceMap: true,
            },
          },
          {
            loader: "postcss-loader",
            options: {
              sourceMap: true,
            },
          },
          {
            loader: "sass-loader",
            options: {
              sourceMap: true,
            },
          },
        ]
      },
    ]
  }
}


